package com.nsn.vs.sdm.component.svn.command;

import org.tmatesoft.svn.core.SVNDepth;
import org.tmatesoft.svn.core.wc.SVNRevision;

import com.nsn.vs.sdm.component.svn.SvnClientManager;

/**
 * Base class for a Command which represents an svn command 
 * such as svn checkout, update and fetch info. 
 * 
 * @author Jeccy.Zhao
 * 
 */
public abstract class SvnCommand 
{
	
	/**
	 * The svn client manager entity
	 */
	protected SvnClientManager svnClient;

	/**
	 * The peg revision
	 */
	protected SVNRevision pegRevision = SVNRevision.HEAD;
	
	/**
	 * The head revision
	 */
	protected SVNRevision revision = SVNRevision.HEAD;
	
	/**
	 * The depth
	 */
	protected SVNDepth depth = SVNDepth.INFINITY;
	
	/**
	 * Force, by default as false
	 */
	protected boolean force = false;
	
	/**
	 * Recursive, by default as true
	 */
	protected boolean recursive = true;
	
	
	/**
	 * The sole constructor
	 * 
	 * @param svnClient
	 *          the svn client manager
	 */
	public SvnCommand (SvnClientManager svnClient) 
	{
		this.svnClient = svnClient;
	}
	
	/**
	 * Executes command 
	 * and return the last-updated revision number property.
	 * 
	 * @return the last-updated revision number
	 * @throws Exception
	 */
	public abstract long execute() throws Exception;
	
	/**
	 * Validates the attributes
	 * 
	 * @throws Exception
	 */
	protected abstract void validateAttributes() throws Exception;
	
	protected boolean isForce() 
	{
		return force;
	}

	protected void setForce(boolean force) 
	{
		this.force = force;
	}

	protected SVNRevision getPegRevision() 
	{
		return pegRevision;
	}

	protected void setPegRevision(SVNRevision pegRevision) 
	{
		this.pegRevision = pegRevision;
	}

	protected SVNRevision getRevision() 
	{
		return revision;
	}

	protected void setRevision(SVNRevision revision) 
	{
		this.revision = revision;
	}

	protected SVNDepth getDepth() 
	{
		return depth;
	}

	protected void setDepth(SVNDepth depth) 
	{
		this.depth = depth;
	}
	
	protected void setRecursive(boolean recursive) 
	{
		this.recursive = recursive;
	}
	
	protected boolean isRecursive() 
	{
		return recursive;
	}

	public SvnClientManager getSvnClient()
	{
		return svnClient;
	}
}
